package org.metasketch.simulator.runtime;

import java.util.ArrayList;
import java.util.List;

import org.metasketch.logger.Log;

public class ProcessManager {

	ResourceResolver resourceResolver;
	Long count = 0l;

	List<SimulationProcess> processes = new ArrayList<SimulationProcess>();

	public void addProcess(SimulationProcess process, Long currentTime) {
		process.setId(++count);
		process.setProcessManager(this);
		processes.add(process);

		// Log.println(currentTime + " - Added new process: " + count + " - "
		// + process.getInitialPetriNet().getName());

	}

	public void remove(SimulationProcess simulationProcess) {
		processes.remove(simulationProcess);

	}

	public void manageCurrentProcesses(Long currentTime) throws Exception {
		List<SimulationProcess> currentProcesses = new ArrayList<SimulationProcess>();
		currentProcesses.addAll(processes);
		for (SimulationProcess process : currentProcesses) {
			process.simulate(currentTime);
		}

	}

	public ResourceResolver getResourceResolver() {
		return resourceResolver;
	}

	public void setResourceResolver(ResourceResolver resourceResolver) {
		this.resourceResolver = resourceResolver;
	}

}
